﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Basmus.Conel
{
    public class StringListBinding : Binding
    {
        public StringListBinding() : base(typeof(string))
        {
            ;
        }

        public override object[] GetElements(object container)
        {
            if (container == null)
                return null;

            var elements = (IList<string>)container;
            return elements.Cast<object>().ToArray();
        }

        public override object GetContainer(object[] elements)
        {
            if (elements == null)
                return null;

            var container = elements.Cast<string>().Select(x => x ?? String.Empty).ToList();
            return container;
        }
    }
}